feat(services): add storage, cache, and DB services#983
Conversation
Adds five read-only service classes used by the upcoming admin
dashboard cards. None are wired into existing controllers yet, so
this change is a pure addition with no behavior change.
* DbHealth - largest tables on MySQL / PostgreSQL
* CachingInfo - OPcache and APCu hit rates plus Redis config
* ExternalStoragesInfo - mounts configured via files_external
* DiskGrowth - rolling history snapshots with a
days-until-full prediction
* TopUsersByQuota - top users ranked by home::*/files size
Signed-off-by: Frank Karlitschek <frank@nextcloud.com>
| } | ||
| $sql = 'SELECT table_name AS name, table_rows AS rows, ' | ||
| . '(data_length + index_length) AS size_bytes ' | ||
| . 'FROM information_schema.TABLES WHERE table_schema = ? ' |
There was a problem hiding this comment.
This definitely needs error handler because by default Nextcloud drops admin privilege by creating a dedicated user during setup.
Checking options …
There was a problem hiding this comment.
It should work when mariadb allows seeing the objects the user has access to. The only remaining issue is that the information_schema access is notorious for rebuilding database metadata.
Accepting the risk for now to get this merged.
| $stmt->bindValue(1, $dbName); | ||
| $result = $stmt->executeQuery(); | ||
| $out = []; | ||
| while (($row = $result->fetch()) !== false) { |
There was a problem hiding this comment.
Prefer using fetchAssociative/fetchNumeric/fetchOne or iterateAssociate/iterateNumeric instead.
| * @return list<array{name: string, rows: int, sizeBytes: int}> | ||
| */ | ||
| private function pgTables(int $limit = 8): array { | ||
| $sql = 'SELECT relname AS name, n_live_tup AS rows, ' |
There was a problem hiding this comment.
Neither pg_class or pg_namespace have a column "n_live_tup".
I'm going to check ...
There was a problem hiding this comment.
pg_stat_user_tables
Should list all tables the current user has access too
| $shouldSample = $history === [] || ($now - $history[count($history) - 1]['ts']) >= self::SAMPLE_INTERVAL; | ||
|
|
||
| if ($shouldSample) { | ||
| $dataDir = (string)$this->config->getSystemValue('datadirectory', ''); |
There was a problem hiding this comment.
I believe the sampling should go to
serverinfo/lib/StorageStatistics.php
Line 57 in d0ea456

Adds five read-only service classes used by the upcoming admin dashboard cards. None are wired into existing controllers yet, so this change is a pure addition with no behavior change.
days-until-full prediction